home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls088.hpux.Z / tls088.hpux / lib / vtcl / tests / forum94 < prev    next >
Encoding:
Text File  |  1995-07-20  |  5.2 KB  |  241 lines

  1. # CVS $Id: forum94,v 1.3 1995/02/03 17:15:37 zibi Exp $
  2.  
  3. #
  4. # Example phone book program explained at forum 93 converted
  5. # to use the new SCO Visual Tcl
  6. #
  7.  
  8.  
  9.  
  10. #
  11. # Strips the widget path off the widget name
  12. #
  13. proc stripPath {path} {
  14.     set pathList [split $path .]
  15.     set nameIndex [expr "[llength $pathList] - 1"]
  16.     set name [lindex $pathList $nameIndex]
  17.     return $name
  18. }
  19.  
  20. #
  21. # Pops down and destroys dialog
  22. #
  23. proc destroyDialogCB {cbs} {
  24.     VtDestroyDialog [keylget cbs dialog]
  25. }
  26.  
  27.  
  28.  
  29.  
  30. #
  31. # Callback for Ok button on Add Screen 
  32. #
  33. proc AddFormOkCB {cbs} {
  34.     
  35.     #
  36.     # get userdata which has form fields
  37.     #
  38.     set FormWidgets [VtGetValues [keylget cbs dialog] -userData]
  39.     set PhoneList   [keylget FormWidgets PhoneList]
  40.  
  41.     set name   [VtGetValues [keylget FormWidgets namefield] -value]
  42.     set number [VtGetValues [keylget FormWidgets numfield]  -value]
  43.     set type   [stripPath \
  44.             [VtGetValues [keylget FormWidgets statusbox] -value]]
  45.  
  46.     AddToPhoneBook $name $number $type $PhoneList
  47.  
  48.     VtDrawnListSelectItem $PhoneList -position 1
  49.  
  50.     VtDestroyDialog [keylget cbs dialog]
  51. }
  52.  
  53.  
  54.  
  55. #
  56. # Callback for Add button on Menu
  57. #
  58. proc PhoneMenuAddCB {cbs} {
  59.  
  60.     set parent [keylget cbs widget]
  61.  
  62.     set addform \
  63.     [VtStartForm $parent.addform             \
  64.         -title "Add"                     \
  65.         -help                            \
  66.         -okCallback AddFormOkCB          \
  67.         -cancelCallback destroyDialogCB]
  68.  
  69.     set namelabel  \
  70.     [VtLabel $addform.namelabel -label "Name:" \
  71.                     -leftSide NONE \
  72.                     -rightSide 20]
  73.  
  74.     set namefield \
  75.     [VtText $addform.namefield -topSide FORM \
  76.                    -rightSide FORM \
  77.                                -leftSide 20]
  78.  
  79.     set numlabel  \
  80.     [VtLabel $addform.numlabel -label "Number:"      \
  81.                    -topSide $namefield   \
  82.                    -leftSide NONE        \
  83.                    -rightSide 20]
  84.  
  85.     set numfield \
  86.     [VtText $addform.numfield  -rightSide FORM   \
  87.                    -below $namefield \
  88.                    -leftSide 20]
  89.  
  90.     set statuslabel  \
  91.     [VtLabel $addform.statuslabel -label "Status:" \
  92.                    -below $numfield    \
  93.                    -leftSide NONE      \
  94.                    -rightSide 20]
  95.  
  96.     set statusbox  \
  97.     [VtRadioBox $addform.statusbox -numColumns 3       \
  98.                        -below $numfield \
  99.                        -leftSide 20     \
  100.                        -rightSide FORM  \
  101.                        -borderWidth 1]
  102.     VtToggleButton $statusbox.friend -label "Friend"   -value 1
  103.     VtToggleButton $statusbox.enemy  -label "Enemy"  
  104.     VtToggleButton $statusbox.turkey -label "Turkey"    
  105.  
  106.  
  107.     #
  108.     # put fields in userData (including phonelist)
  109.     #
  110.     set PhoneList [VtGetValues [keylget cbs dialog] -userData]
  111.     keylset FormWidgets statusbox $statusbox
  112.     keylset FormWidgets namefield $namefield
  113.     keylset FormWidgets numfield  $numfield
  114.     keylset FormWidgets PhoneList $PhoneList
  115.     VtSetValues $addform -userData $FormWidgets
  116.  
  117.     VtShow $addform
  118.     VtSetFocus $namefield
  119. }
  120.  
  121.  
  122.  
  123.  
  124. #
  125. # Callback for Delete button on Menu
  126. #
  127. proc PhoneMenuDeleteCB {cbs} {
  128.  
  129.     set PhoneList [VtGetValues [keylget cbs dialog] -userData]
  130.  
  131.     set pos [VtDrawnListGetSelectedItem $PhoneList -byPositionList]
  132.  
  133.     VtDrawnListSelectItem $PhoneList -next
  134.  
  135.     VtDrawnListDeleteItem $PhoneList -position $pos
  136. }
  137.  
  138.  
  139. #
  140. # Callback for Exit button on Menu
  141. #
  142. proc PhoneMenuExitCB {cbs} {
  143.     VtClose
  144.     exit 0
  145. }
  146.  
  147.  
  148. proc genericCB {cbs} {
  149. }
  150.  
  151. #
  152. # Routine to initially display the menu on the screen
  153. #
  154. proc CreatePhoneBookMenu {form} {
  155.  
  156.     set menuList {
  157.         {pd Phone P}
  158.         {bt Add     A "" "" PhoneMenuAddCB    }
  159.         {bt Delete  D "" "" PhoneMenuDeleteCB }
  160.         {sp}
  161.         {bt Exit    E "" "" PhoneMenuExitCB   }
  162.  
  163.         {pd View V}
  164.         {bt All     A "" "" ""                }
  165.         {bt Friends F "" "" ""                }
  166.         {bt Enemies E "" "" ""                }
  167.         {bt Turkeys T "" "" ""                }
  168.     }
  169.  
  170.     set menubar [VtMenuBar $form.menubar -helpMenuItemList {INDEX}]
  171.     VxMenu $form $menubar $menuList genericCB
  172. }
  173.  
  174.  
  175. #
  176. # Routine to add a name and phone number on the list
  177. #
  178. proc AddToPhoneBook {name phone type PhoneList} {
  179.  
  180.     case $type {
  181.         "friend"   {set icon 0}
  182.         "enemy"    {set icon 1}
  183.         "turkey"   {set icon 2}
  184.     }
  185.  
  186.     VtDrawnListAddItem $PhoneList        \
  187.         -position 1             \
  188.         -fieldList  [list $icon $name $phone]
  189. }
  190.  
  191.  
  192. #
  193. # Routine to initially display the phone list on the screen
  194. #
  195. proc CreatePhoneBookList {form} {
  196.  
  197.     set PhoneList  \
  198.     [VtDrawnList $form.PhoneList \
  199.         -formatList {{ICON 2} {STRING 20} {STRING 15}}  \
  200.         -iconList [list friend.px enemy.px turkey.px]   \
  201.         -CHARM_iconList [list F E T]                    \
  202.         -leftSide FORM                    \
  203.         -rightSide FORM                    \
  204.         -columns 42                                     \
  205.         -rows 5]                                        
  206.         
  207.     AddToPhoneBook  "Shawn McMurdo"  408-429-5192   friend  $PhoneList
  208.     AddToPhoneBook  "Howard Stern"   408-462-5500   turkey  $PhoneList
  209.     AddToPhoneBook  "Rick Solaris"   408-555-7643   enemy   $PhoneList
  210.     AddToPhoneBook  "Bill Windows"   408-437-8455   enemy   $PhoneList
  211.     AddToPhoneBook  "Wing Eng"       408-475-3485   friend  $PhoneList
  212.     AddToPhoneBook  "Julia Dye"      408-435-6532   friend  $PhoneList
  213.  
  214.     VtDrawnListSelectItem $PhoneList -position 1
  215.  
  216.     #
  217.     # put the drawnlist in the form's userdata
  218.     #
  219.     VtSetValues $form -userData $PhoneList
  220. }
  221.  
  222.  
  223. #
  224. # Main
  225. #
  226.  
  227.     set app [VtOpen Example]
  228.  
  229.     VtSetAppValues $app -columnValue MAXIMUM
  230.  
  231.         set mainform [VtStartForm $app.form  \
  232.                  -title "Phone Book"]
  233.  
  234.     CreatePhoneBookMenu $mainform
  235.     CreatePhoneBookList $mainform
  236.  
  237.     VtShow $mainform
  238.     VtMainLoop
  239.  
  240.  
  241.